package com.hxl.controller;


import cn.afterturn.easypoi.excel.ExcelImportUtil;
import cn.afterturn.easypoi.excel.entity.ImportParams;
import cn.hutool.poi.excel.ExcelUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hxl.config.LogAnnotation;
import com.hxl.entity.CmfzBanner;
import com.hxl.entity.CmfzGuru;
import com.hxl.service.CmfzBannerService;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.Banner;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * InnoDB free: 10240 kB 前端控制器
 * </p>
 *
 * @author hxl
 * @since 2020-08-18
 */
/**
@RestController
@RequestMapping("banner")
public class CmfzBannerController {
    @Value("${uploadPath}")
    private String path;
    @Autowired
    private CmfzBannerService cmfzBannerService;
    @GetMapping("banners")
    @LogAnnotation(content = "查看所有轮播图信息",type = "select")
    public Map<String,Object> selectBanners(Integer page,Integer limit){
        Map<String,Object> map = new HashMap<>();
        Page<CmfzBanner> p = cmfzBannerService.selectBanner(page, limit);

        map.put("code",0);
        map.put("msg","");
        map.put("count",p.getTotal());
        map.put("data",p.getRecords());

        return map;
    }

    @GetMapping("add")
    @LogAnnotation(content = "添加图片",type = "insert")
    public Map<String,Object> addBanner(CmfzBanner banner){
        Map<String,Object> map = new HashMap<>();
        banner.setBannerDate(new Date());
        cmfzBannerService.addBanner(banner);
        map.put("code",0);
        map.put("msg","");
        return map;
    }

    @GetMapping("delete")
    @LogAnnotation(content = "删除图片",type = "delete")
    public Map<String,Object> deleteBanner(Integer id){
        Map<String,Object> map = new HashMap<>();
        cmfzBannerService.deleteById(id);
        map.put("code",0);
        map.put("msg","");
        return map;
    }

    @GetMapping("update")
    @LogAnnotation(content = "更新图片",type = "update")
    public Map<String,Object> updateBanner(CmfzBanner banner){
        Map<String,Object> map = new HashMap<>();
        cmfzBannerService.updateBanner(banner);
        map.put("code",0);
        map.put("msg","");
        return map;
    }
    @RequestMapping("upload")
    @LogAnnotation(content = "上传图片",type = "upload")
    public Map<String,Object> pictureUpload(MultipartFile file) throws IOException {
        file.transferTo(new File(path,file.getOriginalFilename()));
        Map<String,Object> map=new HashMap<>();
        map.put("code",0);
        map.put("msg",file.getOriginalFilename());
        return map;
    }
}
*/